package serializer

import (
	"go-shop-admin/internal/model"
	"go-shop-admin/pkg/funs"
	"time"
)

type AuthVO struct {
	ID       uint   `json:"id" _:"comment:登录账号"`
	Account  string `json:"account"   _:"comment:登录账号"`
	Username string `json:"username"  _:"comment:用户名"`
	//Password string `json:"password"  _:"comment:密码 sha1加密"`
	Desc     string ` json:"desc" `
	Phone    string ` json:"phone" binding:"required,checkPhone"`
	Email    string ` json:"email"  binding:"required,email"`
	Avatar   string `json:"avatar"`
	RoleId   uint   ` json:"role_id"  _:"comment:角色表auth_role主键id"`
	LoginNum uint   `json:"login_num"`

	//小程序/公众号 永久二维码
	Status   uint      ` json:"status" _:"comment:状态:0 禁用 1 正常"`
	CreateAt time.Time ` json:"create_at" `
}

// BuildAuth 序列化
func BuildAuth(auth *model.Auth) *AuthVO {
	return &AuthVO{
		ID:       auth.ID,
		Account:  auth.Account,
		Username: auth.Username,
		//Password: auth.Password,
		Desc:     auth.Desc,
		Phone:    funs.AesDeCoding(funs.CutStrNumByScene(auth.Account, 6, 2), auth.Phone),
		Email:    funs.AesDeCoding(funs.CutStrNumByScene(auth.Account, 6, 1), auth.Email),
		Avatar:   funs.JointImageUrl(auth.Avatar),
		RoleId:   auth.RoleId,
		LoginNum: auth.LoginNum + 1,
		Status:   auth.Status,
		CreateAt: auth.CreatedAt,
	}
}
